﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace homework2
{
    internal class Triangle:IShape
    {
        public double[] edges { get; set; } = new double[3];

        public Triangle(double a, double b, double c)
        {
            double[] newedges = { a, b, c };
            edges = newedges;
        }

        public bool isValid()
        {
            return edges[1] > 0 && edges[2] > 0 && edges[0] > 0 && 
                edges[1] + edges[2] > edges[0] &&
                edges[0] + edges[1] > edges[2] && 
                edges[0] + edges[2] > edges[1];
        }

        public double Area
        {
            get
            {
                if (!isValid())
                    throw new InvalidOperationException("三角形边长无效，无法计算");
                double p = (edges[0] + edges[1] + edges[2]) / 2;
                return Math.Sqrt(p * (p - edges[0]) * (p - edges[1]) * (p - edges[2]));
            }
        }
        public string information => $"Triangle[edge[0]:{edges[0]},edge[1]:{edges[1]},edge[2]:{edges[2]}";
    }
}
